{% extends 'base.html' %}

{% load extra %}

{% block content %}

<div class="row">
  <div class="col-xs-12">
    <div class="col-xs-1"><h2><i class="glyphicon glyphicon-{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}signal{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}arrow-up{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}ok{% elif check.polymorphic_ctype.model == 'icmpstatuscheck' %}transfer{% endif %}"></i></h2></div>
    <div class="col-xs-5"><h2>{{ check.name }}</h2></div>
    <div class="col-xs-4 text-right"><h2><span class="label label-{% if check.calculated_status == 'passing' %}success{% else %}danger{% endif %}">{{ check.calculated_status|capfirst }}</span></h2></div>
    <div class="col-xs-2 text-right">
      <h2>
        {% if check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}
          <a href="{% jenkins_human_url check.name %}" class=""><i class="glyphicon glyphicon-link"></i></a>
        {% endif %}
        <a href="{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{% url "update-graphite-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}{% url "update-http-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}{% url "update-jenkins-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'icmpstatuscheck' %}{% url "update-icmp-check" pk=check.id %}{% elif check.edit_url_name %}{% url check.edit_url_name pk=check.id %}{% endif %}" class=""><i class="glyphicon glyphicon-edit"></i>
        <a href="{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{% url "duplicate-graphite-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}{% url "duplicate-http-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}{% url "duplicate-jenkins-check" pk=check.id %}{% elif check.polymorphic_ctype.model == 'icmpstatuscheck' %}{% url "duplicate-icmp-check" pk=check.id %}
          {% elif check.duplicate_url_name %}
            {% url check.duplicate_url_name pk=check.id %}
          {% endif %}" class="">
          <i class="fa fa-copy"></i>
        </a> <a href="{% url "run-check" pk=check.id %}"><i class="glyphicon glyphicon-refresh"></i></a>
      </h2>
    </div>
  </div>
</div>
<hr>
<div class="row">
  <div class="col-xs-12">
    <div class="col-xs-1"><h3><i class="fa fa-list"></i></h3></div>
    <div class="col-xs-11">
      <h3 class="pull-left">Check results</h3>

    {% if checkresults and checkresults.paginator.num_pages > 1 %}
    <ul class="pagination pagination-sm pull-right">
      {% if checkresults.has_previous %}
        <li class="page-item"><a class="page-link" href="?page=1">&laquo;</a></li>
        <li class="page-item"><a class="page-link" href="?page={{ checkresults.previous_page_number }}">{{ checkresults.previous_page_number }}</a></li>
      {% else %}
        <li class="page-item disabled"><a class="page-link" href="#">&laquo;</a></li>
      {% endif %}
        <li class="page-item active"><a class="page-link">{{ checkresults.number }}</a></li>
      {% if checkresults.has_next %}
        <li class="page-item"><a class="page-link" href="?page={{ checkresults.next_page_number }}">{{ checkresults.next_page_number }}</a></li>
        <li class="page-item"><a class="page-link" href="?page={{ checkresults.paginator.num_pages }}">&raquo;</a></li>
      {% else %}
        <li class="page-item disabled"><a class="page-link" href="#">&raquo;</a></li>
      {% endif %}
    </ul>
    {% endif %}

    </div>
  </div>
  <div class="col-xs-12">
    {% if not checkresults %}
      <div class="col-xs-11 col-xs-offset-1">No results for this check</div>
    {% else %}
    <table class="table table-striped table-bordered">
      <thead>
        <tr>
          <th>Status</th>
          <th>Time started</th>
          <th>Time complete</th>
          <th>Took (ms)</th>
          <th>Error</th>
        </tr>
      </thead>
      <tbody>
      {% for result in checkresults %}
        <tr>
          <td>
            <span class="label {% if result.succeeded %}label-success{% else %}label-danger{% endif %}">{{ result.status }}
            </span>
          </td>
          <td>
            <a href="{% url "result" pk=result.id %}">{{ result.time }}</a>
          </td>
          <td>{{ result.time_complete }}</td>
          <td>{{ result.took }}</td>
          <td>{{ result.error|default:"" }}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
    {% endif %}
  </div>
</div>
<hr>
<div class="row">
  {% for service in check.service_set.all %}
  {% if service.hackpad_id or service.runbook_link%}
  <div class="col-xs-12">
    <div class="col-xs-1"><h3><i class="fa fa-exclamation-triangle"></i></h3></div>
    <div class="col-xs-11"><h3>Documentation for linked service <a href="{% url "service" service.id %}">{{ service.name }}</a></h3></div>
    {% if service.runbook_link %}
    <div class="col-xs-11 col-xs-offset-1">
      Runbook Link: <a href="{{ service.runbook_link }}">{{ service.runbook_link }}</a>
    </div>
    {% endif %}
    {% if service.hackpad_id %}
    <div class="col-xs-11 col-xs-offset-1">
      Displaying <a href="{{ service.hackpad_id }}">{{ service.hackpad_id }}</a>:
      <script src="{{ service.hackpad_id }}"></script>
    </div>
    {% endif %}
  </div>
  {% endif %}
  {% endfor %}
</div>
{% endblock content %}

{% block js %}
{% load compress %}
{{ block.super }}
{% compress js %}
<script type="text/coffeescript">

</script>
{% endcompress %}
{% endblock js %}
